#!/bin/bash
# 计算某年:yy某月M有多少天:月份格式:1,2,3,4,5,6,7,8,9,10,11,12
cal_days_in_month()
{
        n_year=$1
        n_month=$2
        n_day=0;
  #echo $n_month
        case $n_month in 1|3|5|7|8|10|12)
                n_day=31;;
        4|6|9|11)
                n_day=30;;
        2)
                if [ `expr $n_year % 4` -eq 0 ];then
                        if [ `expr $n_year % 400` -eq 0 ];then
                                n_day=29;
                        elif [ `expr $n_year % 100` -eq 0 ];then
                                n_day=28;
                        else
                                n_day=29;
                        fi
                else
                        n_day=28;
                fi
        ;;
         esac
         echo ${n_day};
		 return $?;
}

# 获取打印某一天0-23的小时
getHour(){
  n_year=$1
  n_month=$2
  n_day=$3
  n_line=_
  for ((j=0;j<24;j++))
   do
     echo $n_year$n_month$n_day$n_line$j
   done
}

# main执行
zero=0
year=$1
month=$2
#判断月份为数字
expr $1 "+" 10 &> /dev/null
if [ $? -eq 0 ];then
  echo "year: $1 is number"
else
  echo "year: $1 not number---->exit"
  exit 0
fi

expr $2 "+" 10 &> /dev/null
if [ $? -eq 0 ];then
  echo "month: $2 is number"
else
  echo "month: $2 not number---->exit"
  exit 0
fi


sd=$(cal_days_in_month $year $month)
echo $sd
for ((i=1;i<=$sd;i++))
do
  # month-transfer
  if (($month<10))
  then
   d_month=$zero$month 
  else
   d_month=$month
  fi
  # day-transfer
  if ((i<10))
  then
   day=$zero$i
  else
   day=$i
  fi 
  echo $day;
  getHour $year $d_month $day
done;
